package com.webframe.filter;

import java.io.File;
import java.io.FileFilter;

import org.apache.commons.lang.StringUtils;

public class FileFilterUtils implements FileFilter 
{
   
	/**
	 * 类功能描述：
	 *
	 * Create:      2010/4/7 12:26
	 * Description: 用于根据后缀过滤文件
	 */
	private String[]allowExtensions = new String[]{".jpg",".gif",".png",".icon"};
	private String[]exceptDirectories = new String[]{"cvs","svg","SVG"};
	public String[] getAllowExtensions() 
	{
		return allowExtensions;
	}
	public void setAllowExtensions(String[] allowExtensions) 
	{
		this.allowExtensions = allowExtensions;
	}
	public String[] getExceptDirectories() 
	{
		return exceptDirectories;
	}
	public void setExceptDirectories(String[] exceptDirectories) 
	{
		this.exceptDirectories = exceptDirectories;
	}
	public boolean accept(File file) 
	{
		String fileName = file.getName().toLowerCase();
		if(StringUtils.isNotEmpty(fileName))
		{
			if(file.isDirectory())
			{
				for (String dc : exceptDirectories)
				{
					  if(fileName.equals(dc))
					  {
						  return false;
					  }
				}
				return true;
			}
			for (String allow : allowExtensions)
			{
				if(fileName.endsWith(allow))
					return true;
			}
		}
		return false;
	}
}